<template>
    <div class="tab-box pd10">
        <el-tabs v-model="tabName" class="demo-tabs">
            <el-tab-pane label="会议室" name="room">
                <Room></Room>
            </el-tab-pane>
            <el-tab-pane label="班车" name="car">
                <Car></Car>
            </el-tab-pane>
            <el-tab-pane label="活动" name="activity">
                <Activity></Activity>
            </el-tab-pane>
            <el-tab-pane label="订水订餐" name="order">
                <Order></Order>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script setup>
    import { reactive,ref,getCurrentInstance,toRefs,toRaw } from 'vue'
    import { Back,Edit,Delete } from '@element-plus/icons-vue'
    import Editer from '../../components/editer.vue'
    import upfileSingle from '../../components/upfile_single.vue'
    import Room from './room.vue'
    import Car from './car.vue'
    import Activity from './activity.vue'
    import Order from './order.vue'

    let { proxy } = getCurrentInstance()
    let obj = reactive({
        tabName: 'room',
        isEdit: 0,
        total: 0,
        list:[],
        sifterForm: {
            key: '',
            currentpage: 1,
            pagesize: 10
        },
        form: {
            "repair_id":"0",
            "title":"",
            "msg":"",
            "imgs_old":"",
            "imgs":""
        },
        ruleFormRef: null,
    });

    const updalist = (form)=>{
        let param = {
            ...obj.sifterForm,
            ...form
        }
        proxy.$ajax({url: 'repair/list',data: param,bfLoading: true}).then(d => {
            console.log(d);
            if(d.success){
                total.value = d.msg.count||0
                list.value = d.msg.list;
            }else{}
        }).catch(e => {
            console.log(e)
            if(e == "登录已过期，请重新登录"){
                proxy.routerPushMixin('/')
            }
        })
    }
    updalist();

    const delData = (item)=>{
            proxy.$ajax({url: 'repair/delete',data:{repair_id:item.repair_id},bfLoading: true}).then(d => {
                console.log(d);
                if(d.success){
                    proxy.elMessageMixin('删除成功！', 'success')
                    updalist()
                }else{proxy.elMessageMixin(date.err, 'error')}
            }).catch(e => {
                if(e == "登录已过期，请重新登录"){
                    proxy.routerPushMixin('/')
                }
            })
    }

    const re_turn = ()=>{
        isEdit.value = 0;
        form.value = {
            "repair_id":"0",
            "title":"",
            "msg":"",
            "imgs_old":"",
            "imgs":""
        }
    }

    const editData = (item,isEditidx)=>{
        console.log(item);
        if(item){
            proxy.$ajax({url: 'repair/get',data:{repair_id:item.repair_id},bfLoading: true}).then(d => {
                console.log(d);
                if(d.success){
                    form.value = {
                        ...d.msg,
                        repair_id: item.repair_id,
                        imgs_old: form.value.imgs
                    }
                    isEdit.value = isEditidx||2
                }else{}
            }).catch(e => {
                console.log(e)
                if(e == "登录已过期，请重新登录"){
                    proxy.routerPushMixin('/')
                }
            })
        }else{
            isEdit.value = 1
        }
    }

    const submit = ()=>{
      if (ruleFormRef) {
        ruleFormRef.value.validate((valid) => {
          if (valid) {
                console.log(form.value);
                let param = {
                    ...form.value,
                    repair_id:form.value.repair_id||0
                }
                // return 
                proxy.$ajax({url: 'repair/design',data:param,bfLoading: true}).then(d => {
                    console.log(d);
                    if(d.success){
                        form.value = {
                            "repair_id":"0",
                            "title":"",
                            "msg":"",
                            "imgs_old":"",
                            "imgs":""
                        }
                        proxy.elMessageMixin('编辑成功！', 'success')
                        isEdit.value = 0
                        updalist()
                    }else{proxy.elMessageMixin(date.err, 'error')}
                }).catch(e => {
                    console.log(e)
                    if(e == "登录已过期，请重新登录"){
                        proxy.routerPushMixin('/')
                    }
                })
          } else {
            return false;
          }
        });
      }
    }
    
    let { tabName,list, sifterForm, form, isEdit, ruleFormRef, types, verifys, total } = toRefs(obj)
</script>

<style lang="scss" scoped>
</style>